# -*- coding: utf-8 -*-
__author__ = 'chen'

import numpy as np

print(np.linspace(1, 20, 100, dtype=np.float32))
print("*" * 20)

a = np.array([20, 30, 40, 50])
b = np.arange(4)
print(b)

c = a - b
print(c)
print("*" * 20)

a = np.ones((3, 4), dtype=np.int32)
b = np.random.random((3, 4))
print(a)
print("*" * 20)
print(b)
print("*" * 20)
b += a
print(b)
print("*" * 20)

a = np.ones((3, 4), dtype=np.float32) * 3
b = np.random.random((3, 4))
print(a)
a += b
print(a)
print("*" * 20)

b = np.array([1, 2, 3, 4])
print(b * 2)
print(b ** 3)
print("*" * 20)

c = 10 * np.sin(b)
print(c)
print(c < 15)
print("*" * 20)

a = np.arange(12).reshape(3, 4)
print(a)
print(a.sum(axis=0))
print(a.min(axis=0))
print(a.min(axis=1))
print("=" * 20)
print(a.cumsum(axis=1))
print("=" * 20)
# 反转
print(a)
print(a[::-1])

# 迭代
for row in a:
    print(row)

for element in a.flat:
    print(element)

# 合并数组
print("合并数组")
a = np.ones((2, 2))
print(a)
b = np.eye(2)
print(b)
print("=" * 20)
# c = np.vstack((a,b))
c = np.hstack((a, b))
print(c)

# 数组深度拷贝
print("数组的深度拷贝")
a = np.array(([1, 2], [2, 3]))
b = a
print(b is a)
c = a.copy()
print(c is a)
c[0][0] = 20

# 矩阵转置
print("矩阵转置")
a = np.array([[0, 2], [1, 3]])
b = a.transpose()
print(a)
print(b)

# 数组的形状操作
print('数组的形状操作')
a = np.floor(10 * np.random.random((3, 4)))
print(a)
print(a.shape)
print(a.ravel())
print(a.reshape(3, 4))

# resize
print('=' * 10 + 'resize' + '=' * 10)
a = np.array([[1, 2, 3], [4, 5, 6]])
print(a)
a.resize(3, 2)
print(a)
